from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional

class RoleBase(BaseModel):
    # 必填字段
    role_code: str = Field(..., description="角色编码", max_length=50)
    role_name: str = Field(..., description="角色名称", max_length=50)
    
    # 可选字段
    role_desc: Optional[str] = Field(None, description="角色描述", max_length=200)
    status: int = Field(1, description="状态：0-禁用 1-启用")

class RoleCreate(RoleBase):
    """创建角色时使用的模型"""
    
    class Config:
        from_attributes = True

class RoleUpdate(BaseModel):
    """更新角色时使用的模型"""
    role_code: Optional[str] = None
    role_name: Optional[str] = None
    role_desc: Optional[str] = None
    status: Optional[int] = None
    
    class Config:
        from_attributes = True

class Role(RoleBase):
    id: int
    create_time: Optional[datetime] = Field(None, description="创建时间")
    update_time: Optional[datetime] = Field(None, description="更新时间")
    
    class Config:
        from_attributes = True